unit PoslovniPartnerFrm;

interface

uses
  Windows, Classes,
  Controls, StdCtrls, ExtCtrls, ActnList, StdActns,
  DB, DBClient, alBaseDataSet, MConnect,
  Forms, SifrantFrm,
  PoslovanjeSrv_TLB, 
  cxClasses, cxControls, cxGraphics, cxContainer, cxStyles, cxEditRepositoryItems,
  cxCustomData, cxData, cxFilter,
  cxEdit, cxDBEdit, cxTextEdit, cxDBData,
  cxGrid, cxGridLevel, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxDBEditRepository,
  cxGridDBTableView, cxCheckBox, cxMaskEdit, cxDropDownEdit, cxLookupEdit,
  cxDBLookupEdit, cxDBLookupComboBox, ImgList, cxDataStorage, kdbinfo, kdbstruc,
  cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, dxSkinsDefaultPainters,
  dxSkinscxPCPainter;

type
  TfrmPoslovniPartner = class(TfrmSifrant)
    scnPosta: TSharedConnection;
    dtsrcPosta: TDataSource;
    cdsPosta: TBaseDataSet;
    scnPravniStatus: TSharedConnection;
    cdsPravniStatus: TBaseDataSet;
    dtsrcPravniStatus: TDataSource;
    cdsRacun: TBaseDataSet;
    dtsrcRacun: TDataSource;
    rpstMainUlica: TcxEditRepositoryTextItem;
    rpstMainPostaNaziv: TcxEditRepositoryLookupComboBoxItem;
    rpstMainDavcniZavezanec: TcxEditRepositoryCheckBoxItem;
    rpstMainDavcnaStevilka: TcxEditRepositoryMaskItem;
    rpstMainMaticnaStevilka: TcxEditRepositoryMaskItem;
    rpstMainPravniStatusNazivEdit: TcxEditRepositoryLookupComboBoxItem;
    chkbxDavcnaZavezanec: TcxDBCheckBox;
    edtDavcnaStevilka: TcxDBMaskEdit;
    edtMaticnaStevilka: TcxDBMaskEdit;
    lblMaticnaStevilka: TLabel;
    lblRacun: TLabel;
    grdtvRacun: TcxGridDBTableView;
    grdlvlRacun: TcxGridLevel;
    grdRacun: TcxGrid;
    grdtvRacunID: TcxGridDBColumn;
    grdtvRacunRefID: TcxGridDBColumn;
    grdtvRacunNaziv: TcxGridDBColumn;
    grdtvMainDavcnaStevilka: TcxGridDBBandedColumn;
    grdtvMainDavcniZavezanec: TcxGridDBBandedColumn;
    scnRacun: TSharedConnection;
    rpstMainPostaSifra: TcxEditRepositoryLookupComboBoxItem;
    lblUlica: TLabel;
    edtUlica: TcxDBTextEdit;
    lblPosta: TLabel;
    lkpcbPostaSifra: TcxDBLookupComboBox;
    lkpcbPosta: TcxDBLookupComboBox;
    lblPravniStatus: TLabel;
    lkpcbPravniStatus: TcxDBLookupComboBox;
    lblRokPlacila: TLabel;
    edtRokPlacila: TcxDBMaskEdit;
    lblSkupina: TLabel;
    lkpcbSkupina: TcxDBLookupComboBox;
    scnSkupina: TSharedConnection;
    cdsSkupina: TBaseDataSet;
    dtsrcSkupina: TDataSource;
    rpstMainRokPlacila: TcxEditRepositoryMaskItem;
    grdtvMainMaticnaStevilka: TcxGridDBBandedColumn;
    grdtvMainRokPlacila: TcxGridDBBandedColumn;
    rpstMainSkupinaNazivEdit: TcxEditRepositoryLookupComboBoxItem;
    rpstMainRacunID: TcxEditRepositoryMaskItem;
    rpstMainRacunRazredID: TcxEditRepositoryMaskItem;
    rpstMainRacunRefID: TcxEditRepositoryMaskItem;
    rpstMainRacunNaziv: TcxEditRepositoryMaskItem;
    grdtvRacunRazredID: TcxGridDBColumn;
    rpstMainPravniStatusNaziv: TcxEditRepositoryTextItem;
    rpstMainSkupinaNaziv: TcxEditRepositoryTextItem;
    grdtvMainSkupinaNaziv: TcxGridDBBandedColumn;
    procedure OnNewRecord(DataSet: TDataSet);
    procedure OnChange(Sender: TObject);
    procedure OnEnter(Sender: TObject);
    procedure OnExit(Sender: TObject);
  private
    { Private declarations }
  protected
    procedure Deinitialize; override;
    procedure DoDBRefresh; override;
    procedure Initialize; override;
    procedure Loaded; override;
    procedure SetDefaultControl; override;
  public
    { Public declarations }
  end;

var
  frmPoslovniPartner: TfrmPoslovniPartner;

implementation

uses
  MainFrm;

{$R *.dfm}

{ TfrmPoslovniPartner }

procedure TfrmPoslovniPartner.Deinitialize;
begin
  cdsRacun.Close;
  cdsSkupina.Close;
  cdsPravniStatus.Close;
  cdsPosta.Close;
  inherited;
end;

procedure TfrmPoslovniPartner.DoDBRefresh;
begin
  inherited;
  cdsPosta.Refresh;
  cdsPravniStatus.Refresh;
  cdsSkupina.Refresh;
end;

procedure TfrmPoslovniPartner.Initialize;
begin
  inherited;
  cdsPosta.Open;
  cdsPravniStatus.Open;
  cdsSkupina.Open;
  cdsRacun.Open;
end;

procedure TfrmPoslovniPartner.Loaded;
begin
  inherited;
  with grdtvRacun do
  begin
    grdtvRacunID.Visible := False;
    grdtvRacunRazredID.Visible := False;
    grdtvRacunRefID.Visible := False;
  end;
end;

procedure TfrmPoslovniPartner.OnChange(Sender: TObject);
begin
  inherited;
  if Sender = chkbxDavcnaZavezanec then
  begin
    if (Sender as TcxDBCheckBox).Checked then
      edtDavcnaStevilka.Enabled := True
    else
      edtDavcnaStevilka.Enabled := False;
  end;
end;

procedure TfrmPoslovniPartner.OnEnter(Sender: TObject);
begin
  inherited;
  if Sender = grdRacun then
  begin
    KeyPreview := False;
    DataSource := dtsrcRacun;
  end;
end;

procedure TfrmPoslovniPartner.OnExit(Sender: TObject);
begin
  inherited;
  if Sender = grdRacun then
  begin
    DataSource := RootDataSource;
    KeyPreview := True;
  end;
end;

procedure TfrmPoslovniPartner.OnNewRecord(DataSet: TDataSet);
begin
  inherited;
  if DataSet = cdsRacun then
  begin
    DataSet.FieldByName('REF_ID').Value := cdsMain.FieldByName('ID').Value;
  end;
end;

procedure TfrmPoslovniPartner.SetDefaultControl;
begin
  if DataSource = RootDataSource then
    inherited;
end;

end.
